<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box{
            width: 100%;
        }
        .box1{
            width: 100%;
            height: 50px;
            background: lavender;
        }
        .btn{
            background: orange;
            color: white;
            border: 0;
            width: 80px;
            height: 30px;
            border-radius: 5px;
        }
        .liang{
            background: crimson;
            color: white;
            border: 0;
            width: 100px;
            height: 30px;
            line-height: 30px;
            border-radius: 5px;
            margin: 10px;
        }
        .sou{
            width: 150px;
            height: 20px;
            border-radius: 3px;
            margin: 10px;
        }
        table{
            margin-top: 15px;
            width: 100%;
            border-collapse: collapse;
            text-align: center;
            background-color: #dae7ff;
        }
        th{
            border: 1px solid silver;
        }
        th:active{color: red}
        th:hover{color: red}
        td{
            border: 1px solid silver;
        }
            .kuang{
                margin-left:20%;
                font-family: 宋体;
                font-size: 14px;
                font-weight:bold;
            }
        .lyy{
            width: 1000px;
            height: 30px;
            margin-top: 22%;
            margin-left: 48%;
        }
        .sb{
            border: 0;
            background: #2D93CA;
            margin-top: -3px;
            width: 70px;
            height: 30px;
            border-radius: 5px;
        }
        .zhuan1{
            width: 50px;
            height: 20px;
        }
        .zhuan2{
            border: solid;
            color: #2D93CA;
            font-weight: bold;
            font-size: 20px;
            background: transparent;

            border: 0;
        }
        .dao{
            font-family: 黑体;
            font-size: 17px;
        }
        .touxinxi{
            font-size: 14px;
        }
        .tuihuoxinxi{
            width: 30px;
        }

        .yangshi{
            background-color: #b3a4cc;
        }
    </style>
    <script src="/resources/js/jquery-1.7.1.min.js" type="application/javascript"></script>
    <script src="/resources/js/jquery-ui-1.8.10.custom.min.js" type="text/css"></script>
</head>

            <script>
                $(function () {
                    readList(1);
                    $.getJSON("/selectCategory",{},function (data) {
                        var leibie = '<option value="">全部</option>';
                        for(var i = 0 ;i < data.length;i++){
                            var lei = data[i];
                            leibie +='<option value="'+lei.id+'">'+lei.category+'</option>'
                        }
                        $("#leibie").append(leibie);
                    })

                    $.getJSON("/selectProviderIdName",{},function (data) {
                        var gonghuoshang = '<option value="">全部</option>';
                        for(var i = 0 ;i < data.length;i++){
                            var zhi = data[i];
                            gonghuoshang +='<option value="'+zhi.id+'">'+zhi.providerName+'</option>'
                        }
                        $("#gonghuoshang").append(gonghuoshang);
                    })
                })



                var da = "";
                function readList(pageNum) {
                    if(pageNum == 0){
                        pageNum = 1;
                    }
                    var form = $("#form1")[0];
                    var formData= new FormData(form);
                    formData.append("pageNum",pageNum);
                    $.ajax({
                        url:"/selectAddquantity",
                        data:formData,
                        dataTpe:"json",
                        type:"post",
                        processData:false,
                        contentType:false,
                        success:function (data) {
                            da = data;
                            var table = '';
                            var list = data.list;
                            $("#table").empty();
                            for(var i = 0; i < list.length;i++){
                                var zhi = list[i];
                                table +='<tr class="hang">' +
                                    '<td>'+zhi.id+'</td>' +
                                    '<td><input type="checkbox" class="checkMin" value="'+zhi.id+'" onclick="checkMin()"/></td>' +
                                    '<td>'+zhi.purchaseNum+'</td>'+
                                    '<td>'+zhi.purchaseName+'</td>'+
                                    '<td>'+zhi.serialNumber+'</td>'+
                                    '<td>'+zhi.commonName+'</td>'+
                                    '<td>'+zhi.commodityName+'</td>'+
                                    '<td>'+zhi.winPrice+'</td>'+
                                    '<td>'+zhi.trading+'</td>'+
                                    '<td>'+zhi.purchaseAmount+'</td>'+
                                    '<td>'+zhi.purchasePrice+'</td>'+
                                    '<td>'+zhi.inputNum+'</td>'+
                                    '<td>'+zhi.inputPrice+'</td>'+
                                    '<td>'+zhi.invoiceNum+'</td>'+
                                    '<td>'+zhi.batchNumber+'</td>'+
                                    '<td>'+zhi.drugTime+'</td>'+
                                    '<td class="returnsTheAmount"><input type="text" id="returnsTheAmount" class="tuihuoxinxi" name="returnsTheAmount"></td>'+
                                    '<td class="outputPrice"><input type="text" id="outputPrice" class="tuihuoxinxi" name="outputPrice"></td>'+
                                    '<td class="outputDescription"><input type="text" id="outputDescription" class="tuihuoxinxi" name="outputDescription"></td>'+
                                    '<td>'+zhi.dosageForm+'</td>'+
                                    '<td>'+zhi.size+'</td>'+
                                    '<td>'+zhi.unit+'</td>'+
                                    '<td>'+zhi.factor+'</td>'+
                                    '<td>'+zhi.dataName+'</td>'+
                                    '</tr>'
                            }
                            $("#table").append(table);
                        }
                    })
                }


                function jian() {
                    var x = $("input[name='zhuan']").val();
                    readList(x);
                }
                function checkMax() {
                    var check=$(".checkMax").prop("checked");
                    $(".checkMin").prop('checked',check);
                }
                function checkMin() {
                    var chec=true;
                    $.each($(".checkMin"),function (index,item) {
                        if($(item).prop("checked")==false){
                            chec=false;
                        }
                    })
                    $(".checkMax").prop('checked',chec);
                }


                function insertAddquantity() {
                    var idList = new Array();
                    var hospitalOutputDetail = new Array();
                    var formdata = new FormData();
                    $.each($(".checkMin"),function (index,item) {
                        if($(item).prop("checked")==true){
                            idList.push($(item).val());
                        }
                    });
                    if(idList == null || idList == ''){
                        alert("请勾选药品信息！")
                        return;
                    }
                    var outputnum = location.href.split("outputNum=")[1];
                    $.ajax({
                        url:"selectInsertValue",
                        data:{idList:idList},
                        type:"post",
                        dataType:"json",
                        traditional: true,
                        async:false,
                        success:function (data) {
                            for(var i = 0 ; i < data.length;i++){
                                var zhi = data[i];
                                hospitalOutputDetail.push({
                                    purchaseId:zhi.purchaseId,
                                    drugMessageId:zhi.drugMessageId,
                                    outputNum:outputnum,
                                    returnsTheAmount:$("input[name='returnsTheAmount']").val(),
                                    outputState:1,
                                    outputPrice:$("input[name='outputPrice']").val(),
                                    outputDescription:$("input[name='outputDescription']").val(),
                                });
                            }
                            formdata.append("hospitalOutputDetail",JSON.stringify(hospitalOutputDetail))
                        }
                    });
                    $.ajax({
                        url:"/insertAddquantity",
                        data:formdata,
                        dataType:"json",
                        type:"post",
                        traditional: true,
                        async:false,
                        processData: false,
                        contentType: false,
                        success:function (data) {
                            alert("您的操作成功。提交"+data+"数据,成功"+data+"条，失败0条");
                            window.location.reload()//刷新页面
                        }
                    })
                }
                
                function BaoCun() {
                    var idList = new Array();
                    $.each($(".checkMin"),function (index,item) {
                        if($(item).prop("checked")==true){
                            idList.push($(item).val());
                        }
                    });
                    if(idList == null || idList == ''){
                        alert("请勾选药品信息！")
                        return;
                    }
                    if($("input[name='returnsTheAmount']").val() == null || $("input[name='returnsTheAmount']").val() == ''){
                        alert("请输入勾选药品的退货量！")
                        return;
                    }else{
                        document.getElementById("returnsTheAmount").style.border = 0;
                    }

                    if($("input[name='outputPrice']").val() == null || $("input[name='outputPrice']").val() == ''){
                        alert("请输入勾选药品的退货金额！")
                        return;
                    }else{
                        document.getElementById("outputPrice").style.border = 0;
                    }

                    if($("input[name='outputDescription']").val() == null || $("input[name='outputDescription']").val() == ''){
                        alert("请输入勾选药品的退货原因！")
                        return;
                    }else{
                        document.getElementById("outputDescription").style.border = 0;
                    }
                  }
            function delectReturn() {
                var idList = new Array();
                $.each($(".checkMin"),function (index,item) {
                    if($(item).prop("checked")==true){
                        idList.push($(item).val());
                    }
                })
                $.ajax({
                    url:"/delectReturn",
                    data:{idList:idList},
                    dataType:"json",
                    type:"post",
                    traditional: true,
                    async:false,
                    success:function (data) {
                        alert("成功删除"+data+"条数据！")
                        readList(1)
                    }
                })
            }

            </script>
<body>
<div class="box">
    <h3>退货药品添加</h3>
    <hr>
    <div class="yangshi">
    <form action="" method="post" id="form1">
    <div class="kuang">
        &nbsp;
        采购单编号:
        <input type="text" placeholder="输入采购单编号" class="sou" name="purchaseNum"/>
        &nbsp;
        采购单名称:
        <input type="text" placeholder="输入采购单名称" class="sou" name="purchaseName"/>
        &nbsp;&nbsp;
        入库量：
        <input type="text" placeholder="输入入库量" class="sou" name="inputNum">
        <br/>
        &nbsp;&nbsp;
        通用名：
        <input type="text" placeholder="输入通用名" class="sou" name="commonName">
        &nbsp;
        药品流水号：
        <input type="text" placeholder="输入药品流水号" class="sou" name="serialNumber"/>
        &nbsp;&nbsp;&nbsp;
        剂型：
        <input type="text" placeholder="输入剂型" class="sou" name="dosageForm"/>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <br/>
        &nbsp;&nbsp;&nbsp;
        商品名:
        <input type="text" placeholder="输入商品名" class="sou" name="commodityName"/>
        &nbsp;&nbsp;
        质量层次:
        <select class="sou" id="" name="quality">
            <option value="">全部</option>
            <option value=1>国家一类新药</option>
            <option value=2>国家科学进步奖</option>
            <option value=3>专利</option>
            <option value=4>原研</option>
            <option value=5>单独定价</option>
            <option value=6>优质优价</option>
            <option value=7>GMP</option>
        </select>
        &nbsp;&nbsp;
        药品类别:
        <select class="sou" id="leibie" name="category">
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    </form>
    </div>
</div>
<div class="box1">
    &nbsp;&nbsp;
    <button class="liang" onclick="insertAddquantity()">添加到退货单</button>
    <button class="liang" onclick="delectReturn()">删除</button>
    <button class="liang" onclick="BaoCun()">保存退货量</button>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;<button class="liang" onclick="readList(1)">查询</button>
</div>
<table>
    <thead class="touxinxi">
    <tr>
        <th>序号</th>
        <th><input type="checkbox" class="checkMax" onclick="checkMax()"/>全选 </th>
        <th>采购单编号</th>
        <th>采购单名称</th>
        <th>流水号</th>
        <th>通用名</th>
        <th>商品名</th>
        <th>中标价</th>
        <th>交易价</th>
        <th>采购量</th>
        <th>采购金额</th>
        <th>入库量</th>
        <th>实际交易金额</th>
        <th>发票号</th>
        <th>药品批号</th>
        <th>药品有效期</th>
        <th>退货量</th>
        <th>退货金额</th>
        <th>退货原因</th>
        <th>剂型</th>
        <th>规格</th>
        <th>单位</th>
        <th>转换系数</th>
        <th>质量层次</th>
    </tr>
    </thead>
    <tbody id="table">

    </tbody>
</table>
<div class="lyy" style="margin: 10px">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="sb" onclick="readList(1)">首页</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="sb" onclick="readList(da.prePage)">上一页</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="sb" onclick="readList(da.nextPage)">下一页</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="sb" onclick="readList(da.pages)">尾页</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span class="dao">转到</span><input class="zhuan1" name="zhuan" type="text"><span class="dao">页</span><button class="zhuan2"><span class="jian" onclick="jian()">⇨</span></button>
</div>
</body>
</html>
